package edu.ccut.saturn.studio.wfg.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.wfg.model.Shape;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnInformationNode;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnName;

public class SaturnInfoNodeLoader extends NodeLoader{
	
	public List<Shape> loadNodes(Element root) {
		NodeList infoNodes = root.getElementsByTagName(SaturnName.KEY_NODE_ELEMENT_INFORMATION);
		List<Shape> infoList = new ArrayList<Shape>(infoNodes.getLength());
		for(int i = 0 ;i<infoNodes.getLength();i++){
			Node infoNode = infoNodes.item(i);
			SaturnInformationNode info = new SaturnInformationNode();
			info.setId(super.getNodeAttributeValue(infoNode,Shape.KEY_ATTRIBUTE_ID));
			info.setNextId(super.getNodeAttributeValue(infoNode, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID));
			info.setAuthor(super.getNodeElementValue(infoNode, SaturnName.KEY_NODE_ELEMENT_AUTHOR));
			info.setDescription(super.getNodeElementValue(infoNode, Shape.KEY_NODE_DESCRIPTION));
			info.setKey(super.getNodeElementValue(infoNode, SaturnName.KEY_NODE_NAME_KEY));
			info.setVersion(super.getNodeElementValue(infoNode, SaturnName.KEY_NODE_ELEMENT_VERSION));
			info.setLocation(super.getLocation(infoNode));
			info.setName(super.getNodeElementValue(infoNode, Shape.KEY_NODE_NAME));
			info.setSize(super.getSize());
			
			infoList.add(info);
		}
		return infoList;
	}
}
